package com.tricode.ile.training.task.sl275.lab11;

import java.io.*;
import java.util.Scanner;

public class DataSource {

    private File dataFile;

    public DataSource(String dataFilePath) {
        this.dataFile = new File(dataFilePath);
    }

    public void loadData() throws IOException {
        Scanner scanner = new Scanner(dataFile);
        int numOfCustomers = scanner.nextInt();
        for (int i = 0; i < numOfCustomers; i++) {
            String firstName = scanner.next();
            String lastName = scanner.next();
            Customer customer = new Customer(firstName, lastName);
            Bank.addCustomer(customer);
            int numOfAccounts = scanner.nextInt();
            while (numOfAccounts-- > 0) {
                String accountType = scanner.next();
                switch (accountType.charAt(0)) {
                    case 'S': {
                        double balance = scanner.nextDouble();
                        double interestRate = scanner.nextDouble();
                        customer.addAccount(new SavingsAccount(balance, interestRate));
                        break;
                    }
                    case 'C': {
                        double balance = scanner.nextDouble();
                        double overdraft = scanner.nextDouble();
                        customer.addAccount(new CheckingAccount(balance, overdraft));
                        break;
                    }
                }
            }
        }

    }
}
